namespace SMBCFamilyAssessment.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialMigration : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Assessment",
                c => new
                    {
                        AssessmentId = c.Int(nullable: false, identity: true),
                        AssessmentTypeId = c.Int(nullable: false),
                        PersonId = c.Int(nullable: false),
                        AssessmentDate = c.DateTime(nullable: false),
                        DateCreated = c.DateTime(),
                        DateUpdated = c.DateTime(),
                        DatedEnded = c.DateTime(),
                        AssessmentSession_AssessmentSessionId = c.Int(),
                    })
                .PrimaryKey(t => t.AssessmentId)
                .ForeignKey("dbo.AssessmentType", t => t.AssessmentTypeId)
                .ForeignKey("dbo.Person", t => t.PersonId)
                .ForeignKey("dbo.AssessmentSession", t => t.AssessmentSession_AssessmentSessionId)
                .Index(t => t.AssessmentTypeId)
                .Index(t => t.PersonId)
                .Index(t => t.AssessmentSession_AssessmentSessionId);
            
            CreateTable(
                "dbo.AssessmentType",
                c => new
                    {
                        AssessmentTypeId = c.Int(nullable: false, identity: true),
                        Description = c.String(maxLength: 100),
                        Notes = c.String(maxLength: 1000),
                        CreatedDateTime = c.DateTime(),
                        EndedDateTime = c.DateTime(),
                        CreatedBy = c.String(),
                        UpdatedBy = c.String(),
                        AssessmentSession_AssessmentSessionId = c.Int(),
                    })
                .PrimaryKey(t => t.AssessmentTypeId)
                .ForeignKey("dbo.AssessmentSession", t => t.AssessmentSession_AssessmentSessionId)
                .Index(t => t.AssessmentSession_AssessmentSessionId);
            
            CreateTable(
                "dbo.Person",
                c => new
                    {
                        PersonId = c.Int(nullable: false, identity: true),
                        FamilyId = c.Int(nullable: false),
                        FirstName = c.String(maxLength: 35),
                        LastName = c.String(maxLength: 35),
                        DOB = c.DateTime(),
                        Notes = c.String(maxLength: 1000),
                        CreatedBy = c.String(),
                        CreatedDateTime = c.DateTime(),
                        UpdatedBy = c.String(),
                        UpdatedDateTime = c.DateTime(),
                        EndedDateTime = c.DateTime(),
                        AssessmentSession_AssessmentSessionId = c.Int(),
                    })
                .PrimaryKey(t => t.PersonId)
                .ForeignKey("dbo.Family", t => t.FamilyId)
                .ForeignKey("dbo.AssessmentSession", t => t.AssessmentSession_AssessmentSessionId)
                .Index(t => t.FamilyId)
                .Index(t => t.AssessmentSession_AssessmentSessionId);
            
            CreateTable(
                "dbo.Family",
                c => new
                    {
                        FamilyId = c.Int(nullable: false, identity: true),
                        Address1 = c.String(),
                        Address2 = c.String(maxLength: 100),
                        Town = c.String(nullable: false, maxLength: 100),
                        PostCode = c.String(nullable: false, maxLength: 20),
                        FamilyReference = c.String(maxLength: 100),
                        PrimaryPhoneNumber = c.String(),
                        Notes = c.String(maxLength: 1000),
                        CreatedBy = c.String(),
                        CreatedDateTime = c.DateTime(),
                        UpdatedBy = c.String(),
                        UpdatedDateTime = c.DateTime(),
                        EndedDateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.FamilyId);
            
            CreateTable(
                "dbo.AssessmentSession",
                c => new
                    {
                        AssessmentSessionId = c.Int(nullable: false, identity: true),
                        AssessmentId = c.Int(nullable: false),
                        AssessmentTypeId = c.Int(nullable: false),
                        AssessmentSessionDate = c.DateTime(nullable: false),
                        PersonId = c.Int(nullable: false),
                        QuestionSetId = c.Int(nullable: false),
                        QuestionId = c.Int(nullable: false),
                        Score = c.Int(nullable: false),
                        CreatedBy = c.String(),
                        DateCreated = c.DateTime(),
                        DateUpdated = c.DateTime(),
                        DatedEnded = c.DateTime(),
                    })
                .PrimaryKey(t => t.AssessmentSessionId);
            
            CreateTable(
                "dbo.Question",
                c => new
                    {
                        QuestionId = c.Int(nullable: false, identity: true),
                        QuestionSetId = c.Int(nullable: false),
                        QuestionDescription = c.String(maxLength: 1000),
                        CreatedDateTime = c.DateTime(),
                        EndedDateTime = c.DateTime(),
                        CreatedBy = c.String(),
                        UpdatedBy = c.String(),
                        AssessmentSession_AssessmentSessionId = c.Int(),
                    })
                .PrimaryKey(t => t.QuestionId)
                .ForeignKey("dbo.QuestionSets", t => t.QuestionSetId)
                .ForeignKey("dbo.AssessmentSession", t => t.AssessmentSession_AssessmentSessionId)
                .Index(t => t.QuestionSetId)
                .Index(t => t.AssessmentSession_AssessmentSessionId);
            
            CreateTable(
                "dbo.QuestionSets",
                c => new
                    {
                        QuestionSetId = c.Int(nullable: false, identity: true),
                        QuestionSetDescription = c.String(maxLength: 100),
                        Notes = c.String(maxLength: 1000),
                        CreatedDateTime = c.DateTime(),
                        CreatedBy = c.String(),
                        LastModifiedAt = c.DateTime(),
                        LastModifiedBy = c.String(),
                        EndedDateTime = c.DateTime(),
                        AssessmentSession_AssessmentSessionId = c.Int(),
                    })
                .PrimaryKey(t => t.QuestionSetId)
                .ForeignKey("dbo.AssessmentSession", t => t.AssessmentSession_AssessmentSessionId)
                .Index(t => t.AssessmentSession_AssessmentSessionId);
            
            CreateTable(
                "dbo.AssessmentSpecification",
                c => new
                    {
                        AssessmentSpecificationId = c.Int(nullable: false, identity: true),
                        AssessmentTypeId = c.Int(nullable: false),
                        QuestionSetId = c.Int(nullable: false),
                        QuestionSetOrder = c.Int(nullable: false),
                        Notes = c.String(maxLength: 1000),
                        CreatedDateTime = c.DateTime(),
                        EndedDateTime = c.DateTime(),
                        CreatedBy = c.String(),
                        UpdatedBy = c.String(),
                    })
                .PrimaryKey(t => t.AssessmentSpecificationId)
                .ForeignKey("dbo.AssessmentType", t => t.AssessmentTypeId)
                .ForeignKey("dbo.QuestionSets", t => t.QuestionSetId)
                .Index(t => t.AssessmentTypeId)
                .Index(t => t.QuestionSetId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.AssessmentSpecification", "QuestionSetId", "dbo.QuestionSets");
            DropForeignKey("dbo.AssessmentSpecification", "AssessmentTypeId", "dbo.AssessmentType");
            DropForeignKey("dbo.QuestionSets", "AssessmentSession_AssessmentSessionId", "dbo.AssessmentSession");
            DropForeignKey("dbo.Question", "AssessmentSession_AssessmentSessionId", "dbo.AssessmentSession");
            DropForeignKey("dbo.Question", "QuestionSetId", "dbo.QuestionSets");
            DropForeignKey("dbo.Person", "AssessmentSession_AssessmentSessionId", "dbo.AssessmentSession");
            DropForeignKey("dbo.AssessmentType", "AssessmentSession_AssessmentSessionId", "dbo.AssessmentSession");
            DropForeignKey("dbo.Assessment", "AssessmentSession_AssessmentSessionId", "dbo.AssessmentSession");
            DropForeignKey("dbo.Person", "FamilyId", "dbo.Family");
            DropForeignKey("dbo.Assessment", "PersonId", "dbo.Person");
            DropForeignKey("dbo.Assessment", "AssessmentTypeId", "dbo.AssessmentType");
            DropIndex("dbo.AssessmentSpecification", new[] { "QuestionSetId" });
            DropIndex("dbo.AssessmentSpecification", new[] { "AssessmentTypeId" });
            DropIndex("dbo.QuestionSets", new[] { "AssessmentSession_AssessmentSessionId" });
            DropIndex("dbo.Question", new[] { "AssessmentSession_AssessmentSessionId" });
            DropIndex("dbo.Question", new[] { "QuestionSetId" });
            DropIndex("dbo.Person", new[] { "AssessmentSession_AssessmentSessionId" });
            DropIndex("dbo.Person", new[] { "FamilyId" });
            DropIndex("dbo.AssessmentType", new[] { "AssessmentSession_AssessmentSessionId" });
            DropIndex("dbo.Assessment", new[] { "AssessmentSession_AssessmentSessionId" });
            DropIndex("dbo.Assessment", new[] { "PersonId" });
            DropIndex("dbo.Assessment", new[] { "AssessmentTypeId" });
            DropTable("dbo.AssessmentSpecification");
            DropTable("dbo.QuestionSets");
            DropTable("dbo.Question");
            DropTable("dbo.AssessmentSession");
            DropTable("dbo.Family");
            DropTable("dbo.Person");
            DropTable("dbo.AssessmentType");
            DropTable("dbo.Assessment");
        }
    }
}
